<?php

namespace App\Criteria\Student\Student;

use Illuminate\Support\Facades\Input;
use Prettus\Repository\Contracts\CriteriaInterface;
use Prettus\Repository\Contracts\RepositoryInterface;

class StudentBaseQueryCriteria implements CriteriaInterface{

    public function apply($model, RepositoryInterface $repository){
        $name=Input::get('name');
        $census_no=Input::get('census_no');
        $clbum_id=Input::get('clbum_id');
        if($census_no){$model=$model->where('census_no','like','%'.$census_no.'%');}
        if($name){$model=$model->where('student.name','like','%'.$name.'%');}
        if($clbum_id){$model=$model->where('clbum_id','=',$clbum_id);}
        $model=$model->leftJoin('clbum','student.clbum_id','=','clbum.id')
                    ->select('student.*','clbum.name as clbum_name');
        return $model;
    }
}
